<?php
/**
 * Created by PhpStorm.
 * User: yinnannan
 * Date: 16/3/2
 * Time: 下午11:13
 */

class userassert{


    public function getByUserId($parm){
        $result = DB::select('*')->from('sysuserassert')->where('userId','=',$parm['userId'])->execute()->as_array();
        return $result;
    }

    public function createPay($parm){
        $result = DB::select('*')->from('sysuserassert')->where('userId','=',$parm['userId'])->execute()->as_array();
        if(count($result)==0){
            DB::insert("sysuserassert",array('userId','assert'))
                ->values(array($parm['userId'],$parm['money']))
                ->execute();
        }else{
            DB::update("sysuserassert")->set(array('assert'=>$result[0]['assert']+$parm['money']))->where('userId','=',$parm['userId'])->execute();

        }
    }
    public function createScore($parm){
        $result = DB::select('*')->from('sysuserassert')->where('userId','=',$parm['userId'])->execute()->as_array();
        if(count($result)==0){
            DB::insert("sysuserassert",array('userId','score'))
                ->values(array($parm['userId'],$parm['score']))
                ->execute();
        }else{

            DB::update("sysuserassert")->set(array('score'=>$result[0]['score']+$parm['score']))->where('userId','=',$parm['userId'])->execute();

        }
    }
}